﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="VoteMS.UI.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
<form id="form1" runat="server">
    <div>
        请输入项目名称：<asp:TextBox runat="server" ID="txtProjectName"/>
        <asp:Button runat="server" ID="btnSearch" Text="查询" OnClick="btnSearch_Click"/>
    </div>
    <asp:GridView runat="server" ID="gvProjects" AutoGenerateColumns="False" Width="100%">
        <Columns>
            <asp:TemplateField HeaderText="编号">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("ProjectID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="项目名称">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("ProjectName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="类型">
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("TypeName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="所属部门">
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("ProjectDepart") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="得票数">
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("ProjectNumber") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="操作">
                <ItemTemplate>
                    <asp:HyperLink runat="server" NavigateUrl='<%# "Update.aspx?pid=" + Eval("ProjectID") %>' Text="修改"/>||
                    <asp:HyperLink runat="server" NavigateUrl='<%# "javascript:Delete("+Eval("ProjectID")+")" %>' Text="删除"/>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <RowStyle HorizontalAlign="Center" VerticalAlign="Middle"/>
    </asp:GridView>
</form>
    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script>
        function Delete(id) {
            if (window.confirm("确认删除该项目？")) {
                $.ajax({
                    type: 'POST',
                    url: 'DeleteProject.ashx',
                    data: "pid=" + id,
                    success: function (msg) {
                        //TODO json数据转成json对象
                        //var messagejson = JSON.parse(msg);
                        // messagejson.message;
                        // messagejson.code;

                        var result = msg.split('|');
                        alert(result[0]);
                        if (result[1] === "1") {
                            window.location.href = "Default.aspx";
                        }
                    }

                });
            }
        }
    </script>
</body>
</html>
